﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
namespace THS.HtmlHelpers
{
    public static class SiteMapHelper
    {
        /// <summary>
		/// Gets SiteMap path for the current request.
		/// </summary>
		/// <returns></returns>
		public static string SiteMapPath()
		{
           
                var pages = SiteMap.CurrentNode.For(n => n != null, n => n.ParentNode).Reverse().Select(n => SiteMapLink(n));

                return string.Join(" > ", pages.ToArray());
            
          
		}

		/// <summary>
		/// Gets a SiteMap link.
		/// </summary>
		/// <param name="node">The node.</param>
		/// <returns></returns>
		private static string SiteMapLink( SiteMapNode node )
		{
			var span = string.Format( "<span class=\"siteMapLink\">{0}</span>", node.Title );

			return ( node != SiteMap.CurrentNode )
				? string.Format( "<a href=\"{0}\">{1}</a>", node.Url, span )
				: span;
		}
	}

    }
